package com.zjj.algorithm.learning.test;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @author zjj_admin
 * @date 2023/2/5 17:19
 */
public class SolveDemoQuestionByThreadLocal {

    private ThreadLocal<String> name = new ThreadLocal<>();
    private int age;

    public static void main(String[] args) {
        SolveDemoQuestionByThreadLocal demoQuestion = new SolveDemoQuestionByThreadLocal();
        for (int i = 0; i < 5; i++) {
            new Thread(() -> {
                demoQuestion.setName(Thread.currentThread().getName() + "的数据");
                System.out.println("=================");
                System.out.println(Thread.currentThread().getName() + "--->" + demoQuestion.getName());
            }, "t" + i).start();
        }

        ConcurrentHashMap<Object, Object> hashMap = new ConcurrentHashMap<>();
    }

    public String getName() {
        return name.get();
    }

    private void setName(String content) {
        name.set(content);
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
